<#
	Version 1.00 - Share and Permissions for POS
	Date: 20th December 2014
#>



[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 8 ){
Write-host "1. IIS"
Write-host "2. DDS"
Write-host "3. TRADE"
Write-host "4. WAS"
Write-host "5. STG"
Write-host "6. QAS"
Write-host "7. OWB"
Write-host "8. Quit"
[Int]$xMenuChoiceA = read-host "Please enter an option 1 to 8..." }
Switch( $xMenuChoiceA ){
  1{Write-Host Delopying Permission on IIS Nodes -foregroundcolor Black -backgroundcolor Green
	Write-Host -------------------------------------------
		$computers = Get-Content "D:\Powershell\share_computers.txt"
			Invoke-Command -ComputerName $computers {cmd.exe /c net share SOFTWARE /delete /Y}
			Invoke-Command -ComputerName $computers {cmd.exe /c net share Logfiles /delete /Y}
			Invoke-Command -ComputerName $computers {cmd.exe /c net share Logfiles2 /delete /Y}
			Invoke-Command -ComputerName $computers {cmd.exe /c net share Pluginlogs /delete /Y}
			Invoke-Command -ComputerName $computers {cmd.exe /c net share Republish /delete /Y}
			Invoke-Command -ComputerName $computers {cmd.exe /c net share IBM /delete /Y}
			Invoke-Command -ComputerName $computers {New-Item -Type directory D:\Logfiles | Out-Null}
			Invoke-Command -ComputerName $computers {net share SOFTWARE=D:\SOFTWARE "/Grant:IT SRV WEBSPHERE ADMIN,FULL" "/Grant:IT ADM WEBSPHERE ADMIN,FULL"}
			Invoke-Command -ComputerName $computers {cmd.exe /c net share Logfiles=D:\Logfiles "/Grant:IT DAT Beanstore LOGS,Read"}
			Invoke-Command -ComputerName $computers {cmd.exe /c net share Pluginlogs=D:\IBM\Websphere\Plugins\logs  "/Grant:IT DAT Beanstore LOGS,Read"}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\Logfiles" /grant 'IT DAT Beanstore LOGS:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\IBM\Websphere\Plugins\logs" /grant 'IT DAT Beanstore LOGS:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\SOFTWARE" /grant 'IT ADM WEBSPHERE ADMIN:(OI)(CI)F'}
			# Defect : 7605
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Software /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Logfiles /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\IBM\Websphere\Plugins\logs /remove:g Sanjay.Jairam /remove:g balaji.srinivasan /T /Q}
	}
  2{Write-Host Delopying Permission on DDS Nodes -foregroundcolor Black -backgroundcolor Green
	Write-Host -------------------------------------------
		$computers = Get-Content "D:\Powershell\share_computers.txt"
			Invoke-Command -ComputerName $computers {net share SOFTWARE /delete /Y}
			Invoke-Command -ComputerName $computers {net share Custom01 /delete /Y}
			Invoke-Command -ComputerName $computers {net share DATADIST /delete /Y}
			Invoke-Command -ComputerName $computers {net share D_Beanstore /delete /Y}
			Invoke-Command -ComputerName $computers {net share E_Beanstore /delete /Y}
			Invoke-Command -ComputerName $computers {net share DELIVERY /delete /Y}
			Invoke-Command -ComputerName $computers {net share OUTGOING /delete /Y}
			Invoke-Command -ComputerName $computers {New-Item -Type directory D:\datadist | Out-Null}
			Invoke-Command -ComputerName $computers {New-Item -Type directory D:\IBM | Out-Null}
			Invoke-Command -ComputerName $computers {New-Item -Type directory D:\datadist\incoming | Out-Null}
			Invoke-Command -ComputerName $computers {New-Item -Type directory E:\datadist | Out-Null}
			Invoke-Command -ComputerName $computers {New-Item -Type directory E:\datadist\delivery | Out-Null}
			Invoke-Command -ComputerName $computers {New-Item -Type directory E:\datadist\outgoing | Out-Null}
			Invoke-Command -ComputerName $computers {net share SOFTWARE=D:\SOFTWARE "/Grant:IT SRV WEBSPHERE ADMIN,FULL" "/Grant:IT ADM WEBSPHERE ADMIN,FULL"}
			Invoke-Command -ComputerName $computers {net share Custom01=D:\IBM\WebSphere\AppServer\profiles\Custom01 "/Grant:IT DAT Beanstore LOGS,Read"}
			Invoke-Command -ComputerName $computers {net share D_Beanstore=D:\beanstore "/Grant:IT APP Beanstore CONTROLMCOMPUTERNAME user,FULL" "/Grant:IT APP ControlMBatch User,FULL"}
			Invoke-Command -ComputerName $computers {net share E_Beanstore=E:\Beanstore "/Grant:IT APP Beanstore CONTROLMCOMPUTERNAME user,FULL" "/Grant:IT APP ControlMBatch User,FULL"}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\beanstore" /grant 'IT APP Beanstore CONTROLMCOMPUTERNAME user:(OI)(CI)F' /grant 'IT APP ControlMBatch User:(OI)(CI)F' /grant 'system:(OI)(CI)F'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "E:\Beanstore" /grant 'IT APP Beanstore CONTROLMCOMPUTERNAME user:(OI)(CI)F' /grant 'IT APP ControlMBatch User:(OI)(CI)F' /grant 'system:(OI)(CI)F'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\IBM\WebSphere\AppServer\profiles\Custom01" /grant 'IT DAT Beanstore LOGS:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\SOFTWARE" /grant 'IT ADM WEBSPHERE ADMIN:(OI)(CI)F'}
			# Defect : 7605
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\IBM\WebSphere\AppServer\profiles\Custom01 /remove:g Sanjay.Jairam /remove:g balaji.srinivasan /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls E:\Beanstore /remove:g Sanjay.Jairam /remove:g balaji.srinivasan /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Software /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
			Invoke-Command -ComputerName $computers {Remove-Item D:\datadist\incoming -Force -Recurse | Out-Null}
			Invoke-Command -ComputerName $computers {Remove-Item E:\DataDist -Force -Recurse | Out-Null}
	}
  3{Write-Host Delopying Permission on TRADE Nodes -foregroundcolor Black -backgroundcolor Green
	Write-Host -------------------------------------------
		$computers = Get-Content "D:\Powershell\share_computers.txt"
			Invoke-Command -ComputerName $computers {net share SOFTWARE /delete /Y}
			Invoke-Command -ComputerName $computers {net share Custom01 /delete /Y}
			Invoke-Command -ComputerName $computers {net share Republish /delete /Y}
			Invoke-Command -ComputerName $computers {net share IS04Share /delete /Y}
			Invoke-Command -ComputerName $computers {net share IBM /delete /Y}
			Invoke-Command -ComputerName $computers {net share Legacy /delete /Y}
			Invoke-Command -ComputerName $computers {New-Item -Type directory D:\Republish | Out-Null}
			Invoke-Command -ComputerName $computers {Remove-Item D:\legacy -Force -Recurse}
			Invoke-Command -ComputerName $computers {Remove-Item D:\IS04Share -Force -Recurse}
			Invoke-Command -ComputerName $computers {net share SOFTWARE=D:\SOFTWARE "/Grant:IT SRV WEBSPHERE ADMIN,FULL" "/Grant:IT ADM WEBSPHERE ADMIN,FULL"}
			Invoke-Command -ComputerName $computers {net share Custom01=D:\IBM\WebSphere\AppServer\profiles\Custom01 "/Grant:IT DAT Beanstore LOGS,Read"}
			#Invoke-Command -ComputerName $computers {net share Republish=D:\Republish "/Grant:IT SRV Beanstore 3rd Line Support,Read" "/Grant:IT APP ControlMBatch User,Full"}
			Invoke-Command -ComputerName $computers {net share Republish=D:\Republish "/Grant:IT DAT Beanstore Logs,Read" "/Grant:IT APP ControlMBatch User,Full"}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\IBM\WebSphere\AppServer\profiles\Custom01" /grant 'IT DAT Beanstore LOGS:(OI)(CI)R'}
			#Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\Republish" /grant 'IT SRV Beanstore 3rd Line Support:(OI)(CI)R' /grant 'IT APP ControlMBatch User:(OI)(CI)F'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\Republish" /grant 'IT DAT Beanstore Logs:(OI)(CI)R' /grant 'IT APP ControlMBatch User:(OI)(CI)F'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\SOFTWARE" /grant 'IT ADM WEBSPHERE ADMIN:(OI)(CI)F'}
			# Defect : 7605
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\IBM\WebSphere\AppServer\profiles\Custom01 /remove:g Sanjay.Jairam /remove:g balaji.srinivasan /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Software /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Republish /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
	}
  4{Write-Host Delopying Permission on WAS Nodes -foregroundcolor Black -backgroundcolor Green
	Write-Host -------------------------------------------
		$computers = Get-Content "D:\Powershell\share_computers.txt"
			Invoke-Command -ComputerName $computers {net share SOFTWARE /delete /Y}
			Invoke-Command -ComputerName $computers {net share Republish /delete /Y}
			Invoke-Command -ComputerName $computers {net share RM /delete /Y}
			Invoke-Command -ComputerName $computers {net share IBM /delete /Y}
			Invoke-Command -ComputerName $computers {net share Legacy /delete /Y}
			Invoke-Command -ComputerName $computers {net share SOFTWARE=D:\SOFTWARE "/Grant:IT SRV WEBSPHERE ADMIN,Full" "/Grant:IT ADM WEBSPHERE ADMIN,Full"}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\SOFTWARE" /grant 'IT ADM WEBSPHERE ADMIN:(OI)(CI)F'}
	}
  5{Write-Host Delopying Permission on STG Nodes -foregroundcolor Black -backgroundcolor Green
	Write-Host -------------------------------------------
		$computers = Get-Content "D:\Powershell\share_computers.txt"
			Invoke-Command -ComputerName $computers {net share SOFTWARE /delete /Y}
			Invoke-Command -ComputerName $computers {net share Custom01 /delete /Y}
			Invoke-Command -ComputerName $computers {net share IBM /delete /Y}
			Invoke-Command -ComputerName $computers {net share PromotionExtract /delete /Y}
			Invoke-Command -ComputerName $computers {New-Item -Type directory D:\IBM | Out-Null}
			Invoke-Command -ComputerName $computers {net share SOFTWARE=D:\SOFTWARE "/Grant:IT SRV WEBSPHERE ADMIN,FULL" "/Grant:IT ADM WEBSPHERE ADMIN,FULL"}
			Invoke-Command -ComputerName $computers {net share Custom01=D:\IBM\WebSphere\AppServer\profiles\Custom01 "/Grant:IT DAT Beanstore LOGS,Read"}
			Invoke-Command -ComputerName $computers {net share PromotionExtract=D:\PromotionExtract "/Grant:Everyone,Change"}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\IBM\WebSphere\AppServer\profiles\Custom01" /grant 'IT DAT Beanstore LOGS:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\PromotionExtract" /grant 'Y3541223:(OI)(CI)M'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\SOFTWARE" /grant 'IT ADM WEBSPHERE ADMIN:(OI)(CI)F'}
			# Defect : 7605
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Software /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
	}
  6{Write-Host Delopying Permission on QAS Nodes -foregroundcolor Black -backgroundcolor Green
	Write-Host -------------------------------------------
		$computers = Get-Content "D:\Powershell\share_computers.txt"
			Invoke-Command -ComputerName $computers {net share SOFTWARE /delete /Y}
			Invoke-Command -ComputerName $computers {net share A61_Data /delete /Y}
			Invoke-Command -ComputerName $computers {net share ControlM /delete /Y}
			Invoke-Command -ComputerName $computers {net share CMSYSOUT /delete /Y}
			Invoke-Command -ComputerName $computers {net share Integration /delete /Y}
			Invoke-Command -ComputerName $computers {net share BackOffice_Reports /delete /Y}
			Invoke-Command -ComputerName $computers {net share Store_DDS_CSV /delete /Y}
			Invoke-Command -ComputerName $computers {Remove-Item D:\A61_Data -Force -Recurse}
			#Invoke-Command -ComputerName $computers {Import-Csv C:\Powershell\QAS_Folder_Creation.csv | New-Item | Out-Null}
			Invoke-Command -ComputerName $computers {net share SOFTWARE=D:\SOFTWARE "/Grant:IT SRV WEBSPHERE ADMIN,FULL" "/Grant:IT ADM WEBSPHERE ADMIN,FULL"}
			Invoke-Command -ComputerName $computers {net share CMSYSOUT=D:\ControlM\SYSOUT "/Grant:IT APP Beanstore CONTROLMCOMPUTERNAME user,Full" "/Grant:IT DAT Beanstore CONTROLMCOMPUTERNAME user,Full" "/Grant:IT APP ControlMBatch User,Full" "/Grant:everyone,Read" "/Grant:System,Change"}
			Invoke-Command -ComputerName $computers {net share integration=D:\integration "/Grant:IT APP Beanstore CONTROLMCOMPUTERNAME user,Full" "/Grant:IT APP MQFTE Agents,Full" "/Grant:IT APP ControlMBatch User,Full" "/Grant:everyone,Read" "/Grant:System,Change"}
			Invoke-Command -ComputerName $computers {net share BackOffice_Reports=D:\BackOffice_Reports "/Grant:IT APP Beanstore CONTROLMCOMPUTERNAME user,Full" "/Grant:IT DAT BackOffice Reports,READ" "/Grant:IT APP ControlMBatch User,Full" "/Grant:everyone,Read"}
			Invoke-Command -ComputerName $computers {net share Store_DDS_CSV=D:\Store_DDS_CSV "/Grant:IT APP Beanstore CONTROLMCOMPUTERNAME user,Full" "/Grant:IT APP ControlMBatch User,Full" "/Grant:everyone,Read"}
			Invoke-Command -ComputerName $computers {net share ControlM=D:\ControlM "/Grant:IT APP Beanstore CONTROLMCOMPUTERNAME user,Full" "/Grant:IT APP ControlMBatch User,Full" "/Grant:everyone,Read"}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\BackOffice_Reports" /grant 'System:(OI)(CI)F' /grant 'IT APP Beanstore CONTROLMCOMPUTERNAME user:(OI)(CI)F' /grant 'IT DAT BackOffice Reports:(OI)(CI)M' /grant 'IT APP ControlMBatch User:(OI)(CI)F' /grant 'Everyone:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\Store_DDS_CSV" /grant 'System:(OI)(CI)F' /grant 'IT APP Beanstore CONTROLMCOMPUTERNAME user:(OI)(CI)F' /grant 'IT APP ControlMBatch User:(OI)(CI)F' /grant 'Everyone:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\integration" /grant 'System:(OI)(CI)F' /grant 'IT APP Beanstore CONTROLMCOMPUTERNAME user:(OI)(CI)F' /grant 'IT APP ControlMBatch User:(OI)(CI)F' /grant 'Everyone:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\ControlM\SYSOUT" /grant 'System:(OI)(CI)F' /grant 'IT APP Beanstore CONTROLMCOMPUTERNAME user:(OI)(CI)F' /grant 'IT APP ControlMBatch User:(OI)(CI)F' /grant 'Everyone:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\ControlM" /grant 'System:(OI)(CI)F' /grant 'IT APP Beanstore CONTROLMCOMPUTERNAME user:(OI)(CI)F' /grant 'IT APP ControlMBatch User:(OI)(CI)F' /grant 'Everyone:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\SOFTWARE" /grant 'IT ADM WEBSPHERE ADMIN:(OI)(CI)F'}
			# Defect : 7605
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\integration /remove:g 'IT SRV NTSS ADMIN' /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\ControlM\SYSOUT /remove:g 'authenticated user' /T /Q} # Updated script with removal of authenticated user from CMSYSOUT share
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Software /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Software /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
	}
  7{Write-Host Delopying Permission on OWB Nodes -foregroundcolor Black -backgroundcolor Green
	Write-Host -------------------------------------------
		$computers = Get-Content "D:\Powershell\share_computers.txt"
			Invoke-Command -ComputerName $computers {net share Custom01 /delete /Y}
			Invoke-Command -ComputerName $computers {net share SOFTWARE /delete /Y}
			Invoke-Command -ComputerName $computers {net share SOFTWARE=D:\SOFTWARE "/Grant:IT SRV WEBSPHERE ADMIN,FULL" "/Grant:IT ADM WEBSPHERE ADMIN,FULL"}
			Invoke-Command -ComputerName $computers {net share Custom01=D:\IBM\WebSphere\AppServer\profiles\Custom01 "/Grant:IT DAT Beanstore LOGS,Read"}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\IBM\WebSphere\AppServer\profiles\Custom01" /grant 'IT DAT Beanstore LOGS:(OI)(CI)R'}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls "D:\SOFTWARE" /grant 'IT ADM WEBSPHERE ADMIN:(OI)(CI)F'}
			# Defect : 7605
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\IBM\WebSphere\AppServer\profiles\Custom01 /remove:g Sanjay.Jairam /remove:g balaji.srinivasan /T /Q}
			Invoke-Command -ComputerName $computers {cmd.exe /c icacls D:\Software /remove:g balaji.srinivasan /remove:g Sanjay.Jairam /T /Q}
	}
default{<#run a default action or call a function here #>}
}